<?php

class Blog_Message_Sql {
	protected static $_instance;
	protected $message;
	protected $code;

	/**
	 * 
	 * @return Blog_Message_Sql
	 */
	public static function getInstance() {
		if (null === self::$_instance) {
			self::$_instance = new self();
		}
		
		return self::$_instance;
	}
	
	public function setMessage($Message) {
		$this->message = $Message;
		
		return $this;
	}
	
	protected function parse() {
		preg_match('/^SQLSTATE\[(\d+)]\:[a-z0-9\s]+\:\s\d+\s(.*)$/i', $this->message, $matches);
		
		return $matches[2];
	}


	public function getMessage() {
		$Message = $this->parse();
		if (!$Message) {
			return $this->message;
		}
		
		return $Message;
	}
}
?>
